
#include<iostream>
#include<boost/archive/binary_oarchive.hpp>
#include<boost/archive/binary_iarchive.hpp>
#include<sstream>
#include<boost/serialization/vector.hpp>
#include<boost/serialization/map.hpp>
#include"vector_serialization.h"

using namespace std;

string save(vector<string> &svec) {
	ostringstream ostr;
	boost::archive::binary_oarchive oa(ostr);
	oa & BOOST_SERIALIZATION_NVP(svec);
	string out = ostr.str();
	int len = out.size();
	string sl;
	stringstream ss;
	ss << len;
	ss >> sl;
	int i = sl.size();
	sl.insert(i,1,'#');
	sl.insert(0,1,'#');
	out.insert(0,sl);
	return out;
}
string save(map<string,string> &smap) {
	
	ostringstream ostr;
	boost::archive::binary_oarchive oa(ostr);
	oa & BOOST_SERIALIZATION_NVP(smap);
	string out = ostr.str();
	int len = out.size();
	string sl;
	stringstream ss;
	ss << len;
	ss >> sl;
	int i = sl.size();
	sl.insert(i,1,'#');
	sl.insert(0,1,'#');
	out.insert(0,sl);
	return out;
}

void load(string out, vector<string> &recv) {
	istringstream istr(out);
	boost::archive::binary_iarchive ia(istr);
	ia >> BOOST_SERIALIZATION_NVP(recv);
}

void load(string out, map<string,string> &recv) {
	istringstream istr(out);
	boost::archive::binary_iarchive ia(istr);
	ia >> BOOST_SERIALIZATION_NVP(recv);
}
/*
int main(void) {
	map<string,string> smap;
	string key, value;
	for (int i = 0; i < 3; ++i) {
		cout << "key:";
		cin >> key;
		cout << endl;
		cout << "value:";
		cin >> value;
		smap[key] = value;
	}

	string text = save(smap);
	map<string,string> smap1;
	load(text,smap1);
	for (map<string,string>::iterator it = smap1.begin(); it != smap1.end(); ++it) {
		cout << it->first << ":" << it->second << endl;
	}
	return 0;
}*/
